home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / zendisk1.zip / LST7-6.ASM < prev    next >
Assembly Source File  |  1990-02-15  |  2KB  |  79 lines

  1. ;
  2. ; *** Listing 7-6 ***
  3. ;
  4. ; Adds one far array to another far array by temporarily
  5. ; switching segments in order to allow the use of the most
  6. ; efficient possible instructions within the loop.
  7. ;
  8.     jmp    Skip
  9. ;
  10. ARRAY_LENGTH    equ    1000
  11. Array1    db    ARRAY_LENGTH dup (1)
  12. Array2    db    ARRAY_LENGTH dup (2)
  13. ;
  14. ; Adds one byte-sized array to another byte-sized array.
  15. ; C-callable.
  16. ;
  17. ; Input: parameters on stack as in AddArraysParms
  18. ;
  19. ; Output: none
  20. ;
  21. ; Registers altered: AL, BX, CX, ES
  22. ;
  23. ; Direction flag cleared
  24. ;
  25. AddArraysParms    struc
  26.     dw    ?    ;pushed BP
  27.     dw    ?    ;return address
  28. FarPtr1    dd    ?    ;pointer to array to be added to
  29. FarPtr2    dd    ?    ;pointer to array to add to the
  30.             ; other array
  31. AddArraysLength    dw ?    ;# of bytes to add
  32. AddArraysParms    ends
  33. ;
  34. AddArrays    proc    near
  35.     push    bp        ;save caller's BP
  36.     mov    bp,sp        ;point to stack frame
  37.     push    si        ;save register used by many
  38.                 ; C compilers for register
  39.                 ; variables
  40.     push    ds        ;save normal DS, since we're
  41.                 ; going to switch data
  42.                 ; segments for the duration
  43.                 ; of the loop
  44.     mov    cx,[bp+AddArraysLength]
  45.                 ;get the length to add
  46.     les    bx,[bp+FarPtr1]    ;point to the array to add
  47.                 ; to
  48.     lds    si,[bp+FarPtr2]    ;point to the array to add
  49.                 ; from
  50.     cld            ;make LODSB increment SI
  51. AddArraysLoop:
  52.     lodsb            ;get the array element to
  53.                 ; add
  54.     add    es:[bx],al    ;add to the other array
  55.     inc    bx        ;point to the next byte of
  56.                 ; the array to add to
  57.     loop    AddArraysLoop
  58.     pop    ds        ;restore normal DS
  59.     pop    si        ;restore register used by
  60.                 ; many C compilers for
  61.                 ; register variables
  62.     pop    bp        ;restore caller's BP
  63.     ret
  64. AddArrays    endp
  65. ;
  66. Skip:
  67.     call    ZTimerOn
  68.     mov    ax,ARRAY_LENGTH
  69.     push    ax    ;pass the length to add
  70.     push    ds    ;pass segment of Array2
  71.     mov    ax,offset Array2
  72.     push    ax    ;pass offset of Array2
  73.     push    ds    ;pass segment of Array1
  74.     mov    ax,offset Array1
  75.     push    ax    ;pass offset of Array1
  76.     call    AddArrays
  77.     add    sp,10    ;clear the parameters
  78.     call    ZTimerOff
  79.